package com.spring.demo.spring_boot.mapper;

import java.util.Date;
import java.util.List;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.springframework.cache.annotation.Cacheable;

import com.spring.demo.spring_boot.base.mapper.BaseMapper;
import com.spring.demo.spring_boot.domain.UserInfo;

/**
 * 
 * @author 王辉阳
 * @date 2017年8月1日 下午6:11:28
 * @description 用户映射器
 */
@Mapper
public interface UserInfoMapper extends BaseMapper<UserInfo> {
	// 查询后存入redis，建议以方法名
	@Cacheable(value = "get", keyGenerator = "keyGenerator")
	@Select("SELECT * FROM user_info WHERE id = #{id}")
	UserInfo get(@Param("id") String id);

	@Results(value = { //
			@Result(property = "userId", column = "USER_ID", id = true), //
			@Result(property = "userName", column = "USER_NAME"), //
			@Result(property = "userStatus", column = "USER_STATUS"), //
			@Result(property = "userType", column = "USER_TYPE"), //
			@Result(property = "password", column = "PWD"), //
			@Result(property = "createTime", column = "CREATE_TIME", javaType = Date.class) }) //
	@Cacheable(value = "findByName", keyGenerator = "keyGenerator")
	@Select("SELECT * FROM user_info WHERE USER_NAME = #{name}")
	UserInfo findByName(@Param("name") String name);

	@Select("SELECT * FROM user_info  ")
	List<UserInfo> findAll();

	@Select("SELECT * FROM user_info WHERE USER_NAME = #{name}")
	UserInfo getUserByUsername(String name);

}